from main import *
import os

def test_encrypt_facade():
    # 准备测试文件
    test_file = "test_source.txt"
    encrypted_file = "test_encrypted.txt"
    
    # 写入测试内容
    with open(test_file, 'w', encoding='utf-8') as file:
        file.write("Hello, Design Pattern!")
    
    # 使用外观类进行加密
    facade = EncryptFacade()
    facade.file_encrypt(test_file, encrypted_file)
    
    # 验证加密结果
    assert os.path.exists(encrypted_file), "加密文件未生成"
    
    with open(encrypted_file, 'r', encoding='utf-8') as file:
        encrypted_content = file.read()
    
    # 验证加密内容
    assert encrypted_content == "Khoor, Ghvljq Sdwwhuq!", "加密结果不正确"
    
    # 清理测试文件
    os.remove(test_file)
    os.remove(encrypted_file)
    
    print("所有测试通过!")

if __name__ == "__main__":
    # test_encrypt_facade()
    
    # 演示示例
    print("演示示例:")
    facade = EncryptFacade()
    
    # 创建示例文件
    with open("example.txt", 'w', encoding='utf-8') as file:
        file.write("This is a facade pattern example.")
    
    # 使用外观类加密文件
    facade.file_encrypt("example.txt", "example_encrypted.txt")
    
    # 显示加密结果
    with open("example_encrypted.txt", 'r', encoding='utf-8') as file:
        print("加密结果:", file.read())
    
    # 清理示例文件
    # os.remove("example.txt")
    # os.remove("example_encrypted.txt")
